package com.zlm.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 是否提供食宿(0不提供,1包食,2包宿,3包食宿)
 */
public enum IsSuplifeEnum {
    IS_SUPLIFE_0(0,""),
    IS_SUPLIFE_1(1,"包食"),
    IS_SUPLIFE_2(2,"包宿"),
    IS_SUPLIFE_3(3,"包食宿");

    private Integer code;
    private String name;

    private IsSuplifeEnum(Integer code, String name){
        this.code=code;
        this.name=name;
    }

    //把枚举转成json
    public static String getJsonString(){
        StringBuilder builder = new StringBuilder("{");
        for(IsSuplifeEnum isSuplifeEnum:IsSuplifeEnum.values()){
            builder.append("\""+isSuplifeEnum.getCode()+"\":\""+ isSuplifeEnum.getName()+"\",");
        }
        String json=builder.substring(0, builder.length()-1)+"}";
        return json;
    }

    public static List getIsSuplife(){
        List list = new ArrayList();
        Map<String,Object> map;
        for(IsSuplifeEnum isSuplifeEnum:IsSuplifeEnum.values()){
            map= new HashMap<String, Object>();
            map.put("code", isSuplifeEnum.getCode());
            map.put("name", isSuplifeEnum.getName());
            list.add(map);
        }
        return list;
    }

    public static  String getNameByCode(Integer code){
        for(IsSuplifeEnum isSuplifeEnum:IsSuplifeEnum.values()){
            if(code.equals(isSuplifeEnum.getCode())){
                return isSuplifeEnum.getName();
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }



}
